package leetcode.p400;

/**
 * @author: trtan
 * @create: 2021-04-10 09:24
 * @description:
 **/
public class NthDigit {
    public static void main(String[] args) {
        new NthDigit().findNthDigit(1);
    }

    long digitNumber(long x) {
        final int MAX_DIGIT = 9;
        long[] preSum = new long[MAX_DIGIT + 1];
        long[] target = new long[MAX_DIGIT + 1];
        long nums = 9;
        preSum[1] = 1;
        preSum[2] = 10;
        for (int i = 3; i <= MAX_DIGIT; i++) {
            nums = nums * 10 * (i - 1);
            preSum[i] = preSum[i - 1] + nums;
        }
        long[] array = new long[10];
        int d = 0;
        long m = x;
        while (m > 0) {
            d++;
            array[d] = m % 10;
            m /= 10;
        }
        long result = 0;
        for (int i = d; i >= 1; i--) {
            result += preSum[i] * array[i];
        }
        return result;
    }

    public int findNthDigit(int n) {
        int l = 0, r = n;
        while (l < r) {
            int x = (l + r) / 2;
        }
        return 0;
    }
}
